
<?php
    include ('styleadmin/admintop.php');
    include ('styleadmin/adminleft.php');
?> 

<div class ="adcontent">
<?php
$gopy = $_GET['gopy'];
if($gopy == 'view'){
    $sqlgopy = "SELECT t.u_name,s.tensp,g.id,g.hien_thi FROM thanhvien AS t INNER JOIN gopysanpham AS g ON (g.thanhvien_id =t.id) INNER JOIN sanpham AS s ON (g.sanpham_id = s.id) ORDER BY g.id DESC";
    $qrgopy = mysql_query($sqlgopy) or die("không thực hiện được select".mysql_error());
    $num = mysql_num_rows($qrgopy);
        if($num > 0){
            echo "<form method ='post' action ='' id ='form_checkbox' name ='form_checkbox' onsubmit ='return check_checkbox();'>";
            echo "<div class ='divcontent'>";
                echo "<div class ='tieudedm'> Danh sách góp ý sản phẩm </div>";
                echo "<table>";
                    echo "<th>Sản phẩm được góp ý</th><th>Thành viên góp ý</th><th>Tình trạng </th><th>Xem</th><th><input type ='checkbox' id ='checkall' name ='checkall' value ='check_all'  onclick =\"selectReverse('form_checkbox','checkbox');\"/></th>";
                    while($row = mysql_fetch_array($qrgopy)){
                    $idgopy = $row['id'];
                    $tensp = $row['tensp'];
                    $tentv = $row['u_name'];
                    $hienthigy = $row['hien_thi'];
                    if($hienthigy == 1){
                        $hienthigy = " <a href=\"#\" ><span id='hienthi_".$idgopy."'><img  onclick =\"khonghienthigopy('".$idgopy."')\" src ='images/icon-32-publish_01.png' title=\"Hiển thị\"  /></span></a>";
                    }else{
                        $hienthigy = " <a href=\"#\" ><span id='hienthi_".$idgopy."'><img  onclick =\"hienthigopy('".$idgopy."')\" src ='images/icon-32-publish_02.png' title=\"Không hiển thị\"  /></span></a>";
                    }
                    echo "<tr><td style ='width: 65%;'>".$tensp."</td><td style ='width: 15%;'>".$tentv."</td><td  style ='text-align:center; width: 10%;'>".$hienthigy."</td><td style ='width: 5%; text-align: center;'><a href = 'acp_gopy.php?idchitiet=".$idgopy."' title ='Xem nội dung góp ý'><img src ='images/xem.jpg'/></a></td><td  style ='text-align:center; border-right: 0; '><input type ='checkbox' id ='checkbox_' name ='check[]' value ='".$idgopy."'/></td></tr>";
                    }
               echo "</table>";
               echo "<div class = 'divsubmit'><input class ='submittin save' type='submit' name ='xoagopy' id = 'xoagopy' value ='Xóa'/></div>";      
            echo "</div>";
            }else{
                echo "<div class ='tieudedm'> Danh sách góp ý chưa có </div>";
            }
    
}
// xóa góp ý trong cơ sở dữ liệu
if(isset($_POST['xoagopy']) && isset($_POST['check'])){
    $idgopyxoa = $_POST['check'];
    $dem = count($idgopyxoa);
    for($i = 0; $i < $dem ; $i++){
        $xoaidgopy = $idgopyxoa[$i];
        $sqlxoagopy = "DELETE FROM gopysanpham WHERE id =".$xoaidgopy;
        $qrxoaqopy = mysql_query($sqlxoagopy) or die ("không xóa được góp ý".mysql_error());
        if($qrxoaqopy){
            echo "<script> window.location = 'acp_gopy.php?gopy=view' </script>";
        }else{
            echo "<script> alert(' không xóa được góp ý'); </script>";
        }
    }
}

// xem nội dung chi tiết góp ý 
if(isset($_GET['idchitiet'])){
    $xemidgy = $_GET['idchitiet'];
    $sqlctgy = "SELECT t.u_name,s.tensp,g.thoigian_camnhan,g.noidung FROM thanhvien AS t INNER JOIN gopysanpham AS g ON (g.thanhvien_id =t.id) INNER JOIN sanpham AS s ON (g.sanpham_id = s.id) WHERE g.id = ".$xemidgy;
    $qrctgy = mysql_query($sqlctgy) or die ("không xem được chi tiết góp ý".mysql_error());
    $row = mysql_fetch_assoc($qrctgy);
    $tentvgy = $row['u_name'];
    $tespgy = $row['tensp'];
    $noidunggy = $row['noidung'];
    $thoigiangy = $row['thoigian_camnhan'];
    echo "<div class ='divcontent'>";
        echo "<div class ='bgtieude'> chi tiết nội dung góp ý</div>";
            echo "<div class ='khungchitietgopy'>";
                echo "<div class ='tieudegopy'>Thành viên góp ý:</div>";
                echo "<div class='noidunggopy1'>".$tentvgy."</div>";
                echo "<div class ='tieudegopy'>Sản phẩm góp ý:</div>";
                echo "<div class='noidunggopy1'>".$tespgy."</div>";
                echo "<div class ='tieudegopy'>Thời gian góp ý :</div>";
                echo "<div class='noidunggopy1'>".$thoigiangy."</div>";
                echo "<div class ='tieudegopy'>Nội dung góp ý :</div>";
                echo "<div class='noidunggopy2'>".$noidunggy."</div>";
            echo "</div>";
        echo "<div class ='trolai'><a class ='save' href ='acp_gopy.php?gopy=view' title = 'trở lại xem danh sách góp ý'> Trở lại </a></div>";

    echo "</div>";
}

?>



</div>
    
    
 <?php   
    include ('styleadmin/adminfooter.php');
?>